package com.future;

import com.future.util.TreeNode;

public class Solution_isSameTree_100 {

    public static void main(String[] args) {
        TreeNode head = new TreeNode(1);
        head.left = new TreeNode(2);
        head.right = new TreeNode(3);
        head.left.left = new TreeNode(4);
        head.left.right = new TreeNode(5);
        head.right.left = new TreeNode(6);
        head.right.right = new TreeNode(7);

        TreeNode head2 = new TreeNode(1);
        head2.left = new TreeNode(2);
        head2.right = new TreeNode(3);
        head2.left.left = new TreeNode(4);
        head2.left.right = new TreeNode(5);
        head2.right.left = new TreeNode(22);
        head2.right.right = new TreeNode(7);
        System.out.println(isSameTree(head, head2));
        System.out.println("=========");
        head = new TreeNode(1, new TreeNode(2), null);
        head2 = new TreeNode(1, null, null);
        System.out.println(isSameTree(head, head2));
    }

    public static boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null ^ q == null) {
            return false;
        }
        // 目的,把false|true传递出来
        return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }


}
